import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.List;

/**
 * @Author: XuDi
 * @Date: 2022/6/1 17:28
 */
public class BaiLan {
    public JFrame jFrame;
    JPanel jPanel;
    JTextField stuName,phone,stuId,discipline,start,end;//stuName 姓名, phone 手机, stuId 学号, discipline专业班级
    JComboBox sex,college,month;// sex 性别 college 学院  日期：month start & end
    JButton ok;

    public BaiLan(){
        //TODO: logo
        jFrame = new JFrame("柏岚");
        jPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));

        //JTextField
//        discipline = new JTextField(20);
        stuId = new JTextField(13);
        phone = new JTextField(13);
        stuName = new JTextField(20);
        start = new JTextField(2);
        end = new JTextField(2);

        jPanel.add(new JLabel("姓名"));
        jPanel.add(stuName);

        jPanel.add(new JLabel("手机"));
        jPanel.add(phone);

        jPanel.add(new JLabel("学号"));
        jPanel.add(stuId);

//        jPanel.add(new JLabel("专业、班级"));
//        jPanel.add(discipline);


        //性别  组合框
        sex = new JComboBox<String>();
        sex.addItem("男");
        sex.addItem("女");

//        //学院组合框
//        college = new JComboBox<String>();
//        college.addItem("计算机工程学院");
//        college.addItem("机器人学院");
//        college.addItem("外语学院");

        //月份
        month = new JComboBox<>();
        for (int i = 0;i<12;i++){
            month.addItem(i+1);
        }
        ok = new JButton("ok");

        jPanel.add(sex);
//        jPanel.add(college);
        jPanel.add(month);

        jPanel.add(new JLabel("start"));
        jPanel.add(start);
        jPanel.add(new JLabel("end"));
        jPanel.add(end);
        jPanel.add(ok);
        jFrame.add(jPanel);

        ok.addActionListener(
            new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    String stuid = stuId.getText().trim();
                    String name = stuName.getText().trim();
                    String sexual = (String) sex.getSelectedItem();
                    String ph  = phone.getText().trim();
                    int Month = (int) month.getSelectedItem();
                    int dayStart = Integer.parseInt(start.getText().trim());
                    int dayEnd= Integer.parseInt(end.getText().trim());
                    try {
                        Output.outPut(stuid,name,sexual,ph,Month,dayStart,dayEnd);
                        JOptionPane.showMessageDialog(null,"生成成功","提示",JOptionPane.INFORMATION_MESSAGE);
                    } catch (Exception ex) {
                        ex.printStackTrace();
                    }

                }
            }
        );
    }
    public static void main(String[] args) {
        BaiLan baiLan = new BaiLan();
        baiLan.jFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        baiLan.jFrame.setVisible(true);
        baiLan.jFrame.setBounds(600,300,300,450);
    }
}
